USE msdb
GO
SET IDENTITY_INSERT dbo.sysmail_account ON

GO
INSERT INTO [msdb].[dbo].[sysmail_account]
([account_id]
      ,[name]
      ,[description]
      ,[email_address]
      ,[display_name]
      ,[replyto_address]
      ,[last_mod_datetime]
      ,[last_mod_user])
SELECT [account_id]
      ,[name]
      ,[description]
      ,[email_address]
      ,[display_name]
      ,[replyto_address]
      ,[last_mod_datetime]
      ,[last_mod_user]
FROM OPENDATASOURCE('SQLOLEDB','DATA SOURCE=10.125.3.12;USER ID=SA;PASSWORD=1').
[msdb].[dbo].[sysmail_account]
GO
SET IDENTITY_INSERT dbo.sysmail_account OFF
GO

SET IDENTITY_INSERT [dbo].[sysmail_profile] ON
GO
INSERT INTO [msdb].[dbo].[sysmail_profile]
([profile_id]
      ,[name]
      ,[description]
      ,[last_mod_datetime]
      ,[last_mod_user])
SELECT [profile_id]
      ,[name]
      ,[description]
      ,[last_mod_datetime]
      ,[last_mod_user]
FROM OPENDATASOURCE('SQLOLEDB','DATA SOURCE=10.125.3.12;USER ID=SA;PASSWORD=1').
[msdb].[dbo].[sysmail_profile]
GO
SET IDENTITY_INSERT dbo.sysmail_account OFF
GO

INSERT INTO [msdb].[dbo].[sysmail_server]
([account_id]
      ,[servertype]
      ,[servername]
      ,[port]
      ,[username]
      ,[credential_id]
      ,[use_default_credentials]
      ,[enable_ssl]
      ,[flags]
      ,[last_mod_datetime]
      ,[last_mod_user])
SELECT [account_id]
      ,[servertype]
      ,[servername]
      ,[port]
      ,[username]
      ,[credential_id]
      ,[use_default_credentials]
      ,[enable_ssl]
      ,[flags]
      ,[last_mod_datetime]
      ,[last_mod_user]
  FROM OPENDATASOURCE('SQLOLEDB','DATA SOURCE=10.125.3.12;USER ID=SA;PASSWORD=1').
  [msdb].[dbo].[sysmail_server]
  GO


INSERT INTO [msdb].[dbo].[sysmail_profileaccount]
([profile_id]
      ,[account_id]
      ,[sequence_number]
      ,[last_mod_datetime]
      ,[last_mod_user])
SELECT [profile_id]
      ,[account_id]
      ,[sequence_number]
      ,[last_mod_datetime]
      ,[last_mod_user]
  FROM OPENDATASOURCE('SQLOLEDB','DATA SOURCE=10.125.3.12;USER ID=SA;PASSWORD=1').
  [msdb].[dbo].[sysmail_profileaccount]
  GO
